package calvin.study.rabbitmq.advanced.limit;


import java.io.IOException;

import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

import calvin.study.rabbitmq.base.RabbitMqBase;

public class Consumer1 extends RabbitMqBase {
	
	public static void main(String[] args) {
		try {
			ConnectionFactory conFactory = getConnectionFactory();
			Connection connection = conFactory.newConnection();
			Channel channel = connection.createChannel();
			channel.queueDeclare("confirm_queue", true, false, false, null);
			//channel.basicQos(0, 2, false);

			
			DefaultConsumer defaultConsumer = new DefaultConsumer(channel) {
				@Override
				public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties,
						byte[] body) throws IOException {
					System.out.println("消费者1接收消息：" + new String(body));
					channel.basicAck(envelope.getDeliveryTag(), false);
				}
			};
			
			channel.basicConsume("confirm_queue", false,defaultConsumer);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
